﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="getMessenges.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.getMessenges" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <% 
        int mute = int.Parse(Request.QueryString["mute"]);
        if (!String.IsNullOrEmpty(Session["admin_id"].ToString()))
        {
            int get_staff = int.Parse(Session["admin_id"].ToString());
            int? user = 0;
            var check_chat = new TblChatController().FetchAll().ToList();
            if (check_chat.Count != 0)
            {
                var get_messenges = new TblChatController().FetchAll();
                foreach (TblChat messenges in get_messenges)
                {
                    string text = messenges.ChatContent;
                    string[] temp = new string[text.Split(' ').Count()];
                    temp = text.Split(' ');
                    string temp2 = "";
                    for (int i = 0; i < temp.Length; i++)
                    {
                        if (temp[i].Split('_')[0] == "IT'sSQTicons")
                        {
                            temp2 += "<img src='../../Content/img/chat-ico/" + temp[i].Split('_')[1] + "' />";
                        }
                        else
                            temp2 += temp[i];
                        temp2 += " ";
                    }
                    if (get_staff == messenges.Chater)
                    {
    %>
    <div class="messenger-chat w3-row">
        <div class="bubble bubble-alt w3-teal" data-toggle="tooltip" data-placement="left" title="<%=DateTime.Parse(messenges.ChatTime.ToString()).Day+"/"+DateTime.Parse(messenges.ChatTime.ToString()).Month + "/" + DateTime.Parse(messenges.ChatTime.ToString()).Year + " " + DateTime.Parse(messenges.ChatTime.ToString()).Hour +":"+DateTime.Parse(messenges.ChatTime.ToString()).Minute %>">
            <div class="w3-hide chat_id"><%=messenges.ChatId %></div>
            <%=temp2 %>
        </div>
    </div>
    <%
                    }
                    else
                    {
                        var get_user = new TblManagerController().FetchAll().Where(x => x.ManagerId == messenges.Chater).Single();
    %>
    <div class="messenger-chat w3-row">
        <a data-toggle="tooltip" data-placement="left" title="<%=get_user.FullName %>" class="us-img">
            <img src="../../Content/avatar/<%=get_user.Avatar %>" class="w3-circle w3-col" /></a>
        <div class="bubble bt-simple-grey w3-col" data-toggle="tooltip" data-placement="right" title="<%=DateTime.Parse(messenges.ChatTime.ToString()).Day+"/"+DateTime.Parse(messenges.ChatTime.ToString()).Month + "/" + DateTime.Parse(messenges.ChatTime.ToString()).Year + " " + DateTime.Parse(messenges.ChatTime.ToString()).Hour +":"+DateTime.Parse(messenges.ChatTime.ToString()).Minute %>">
            <div class="w3-hide chat_id"><%=messenges.ChatId %></div>
            <%=temp2 %>
        </div>
    </div>

    <%
                    }
                    user = messenges.Chater;
                }
                if (mute == 0)
                {
                    if (user != int.Parse(Session["admin_id"].ToString()))
                    {
    %>
    <audio src="../../Content/testdata/audio/Notification.mp3" class="notification" autoplay="autoplay" />
    <%
                    }
                }
            }
        }
    %>
</body>
</html>
